package com.zryc.shop.sms.controller;

import com.zryc.shop.base.Result;
import com.zryc.shop.sms.entity.Coupon;
import com.zryc.shop.sms.service.ICouponService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

/**
 * <p>
 * 优惠券表 前端控制器
 * </p>
 *
 * @author zhaozhao
 * @since 2024-01-18
 */
@RestController
@RequestMapping("/sms/coupon")
public class CouponController {

    @Autowired
    private ICouponService couponService;

    @GetMapping("/list")
    @ApiOperation("优惠券列表")
    public Result list(@RequestParam(required = false) @ApiParam(value = "优惠券名称关键词") String name,
                       @RequestParam(required = false) @ApiParam(value = "赠券类型") Integer type,
                       @RequestParam(defaultValue = "1") @ApiParam(value = "页码", required = true) Integer pageNum,
                       @RequestParam(defaultValue = "10") @ApiParam(value = "每页显示条数", required = true) Integer pageSize){
        return Result.ok(couponService.list(name,type,pageNum,pageSize));
    }

    @GetMapping("/{id}")
    @ApiOperation("查询优惠券信息")
    public Result info(@PathVariable @ApiParam(value = "优惠券ID", required = true) Long id){
        return Result.ok(couponService.detail(id));
    }

    @PostMapping("/create")
    @ApiOperation("添加优惠券")
    public Result create(@RequestBody Coupon coupon){
        return Result.ok(couponService.create(coupon));
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("删除优惠券")
    public Result delete(@PathVariable @ApiParam(value = "优惠券ID", required = true) Long id){
        return Result.ok(couponService.deleteCoupon(id));
    }

    @PostMapping("/update/{id}")
    @ApiOperation("更新优惠券")
    public Result update(@PathVariable @ApiParam(value = "优惠券ID", required = true) Long id,
                                 @RequestBody Coupon coupon){
        return Result.ok(couponService.updateCoupon(id,coupon));
    }
}
